<template>
	<div id="writerInfo" v-if="info.userID">
		<img :src="ip+'/'+info.userID.imgurl" />
		<div id="writerInfoCenter">
			<div id="writeName">{{info.userID.name}}</div>
			<div id="contextInfo">
				<div class="contextInfoDetail">{{$dateFormate.dateFormate("YYYY-mm-dd HH:MM:SS", info.createTime)}}</div>
				<div class="contextInfoDetail">字数：{{info.text.length}}</div>
				<div class="contextInfoDetail">阅读：156</div>
			</div>
		</div>
		<div id="isAttentionBtn" v-if="attention" @mouseover="changeInfo" @mouseout="changeInfo">{{attenInfo}}</div>
		<div id="attentionBtn" @click="atten" v-else>关注</div>
	</div>
</template>

<script>
	export default {
		props: ['info','attentionInfo'],
		data(){
			return {
				attenInfo: '已关注',
				attention: this.$props.attentionInfo
			}
		},
		methods:{
			atten(){
				this.$axios({
					url: this.ip + '/attention',
					method: 'post',
					data: {
						userID: this.$storage.get('user').id,
						attentionID: this.$props.info.userID._id
					}
				}).then(res => {
					console.log(res.data)
					this.$emit('attentionOver')
					this.attention = true
				})
			},
			changeInfo(){
				if(this.attenInfo == "已关注"){
					this.attenInfo = "取消关注"
				}else{
					this.attenInfo = "已关注"
				}
			}
		}
	}
</script>

<style>
	#writerInfo {
		height: 56px;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-bottom: 1px solid #EEEEEE;
	}

	#writerInfo img {
		width: 50px;
		height: 50px;
		display: block;
		border-radius: 50%;
	}

	#writerInfo #writerInfoCenter {
		margin-left: 16px;
		width: 482px;
	}

	#writerInfo #writerInfoCenter #writeName {
		height: 24px;
		font-size: 18px;
		line-height: 24px;
	}

	#writerInfo #writerInfoCenter #contextInfo {
		height: 20px;
		display: flex;
	}

	#writerInfo #writerInfoCenter #contextInfo .contextInfoDetail {
		margin-right: 10px;
		line-height: 20px;
		font-size: 12px;
		color: #969696;
	}
	#writerInfo #attentionBtn ,#writerInfo #isAttentionBtn{
		height: 30px;
		line-height: 30px;
		text-align: center;
		border: 1px solid #996699;
		border-radius: 15px;
		font-size: 16px;
		cursor: pointer;
		user-select: none;
		transition: all .3s;
	}
	#writerInfo #attentionBtn {
		width: 65px;
		color: #996699;
		background-color: white;
	}
	
	#writerInfo #attentionBtn:hover {
		background-color: #996699;
		color: white;
	}
	
	#writerInfo #isAttentionBtn{
		width: 100px;
		color: white;
		background-color: #996699;
	}
	#writerInfo #isAttentionBtn:hover {
		background-color: white;
		color: #996699;
	}
</style>
